package com.jlnx.controller.bank;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlnx.dao.ChainEnterpriseDaoImpl;
import com.jlnx.dao.CoreEnterpriseDaoImpl;
import com.jlnx.dao.EnterpriseDaoImpl;
import com.jlnx.dao.FinanceReqDaoImpl;
import com.jlnx.pojo.ChainEnterprise;
import com.jlnx.pojo.CoreEnterprise;
import com.jlnx.pojo.Enterprise;
import com.jlnx.pojo.FinanceReq;

/*
 * 同意准入
 */
@WebServlet("/RefuseFinanceReqController")
public class RefuseFinanceReqController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获取请求信息
		response.setContentType("application/json;charset=UTF-8;text/html");
		//设置请求编码模式
    	request.setCharacterEncoding("utf-8");
    	
    	int retId = Integer.parseInt(request.getParameter("reqId"));
    	String message = request.getParameter("message");
    	
		 FinanceReqDaoImpl dao = new FinanceReqDaoImpl();
				
		 //获取session对象
		 HttpSession hs=request.getSession();
		 //获取登录账号
		 String bankentNo = ((Enterprise)hs.getAttribute("enterprise")).getEntNo();
		 System.out.println( bankentNo + ":拒绝id" + retId + "融资");
		 
	     //获取融资信息，添加拒绝信息
		 FinanceReq financeReq = dao.selectByReqId(retId);
         financeReq.setReqMassage(message);
         if(dao.changeReqMessageById(retId, message) < 0) {
				//TODO 失败处理
			 request.setAttribute("isRequestSuccess", false);
			 request.setAttribute("message", "请求失败!");
			 request.getRequestDispatcher("/FinanceHandleController").forward(request, response);
         }else {
			 if(dao.changeReqStatusById(retId, 1) < 0) {
				//TODO 失败处理
				 request.setAttribute("isRequestSuccess", false);
				 request.setAttribute("message", "请求失败!");
				 request.getRequestDispatcher("/FinanceHandleController").forward(request, response);
			 }else {
				 request.setAttribute("isRequestSuccess", true);
				 request.setAttribute("message", "拒绝成功!");
				 request.getRequestDispatcher("/FinanceHandleController").forward(request, response);
			 }
         }




		//发起还款，修改还款状态
//		if(dao.returnById(reqId)<0) {
//			request.getRequestDispatcher("/main/returnReq.jsp").forward(request, response);
//		}else {
//			request.getRequestDispatcher("/ReturnStatusSearchController").forward(request, response);
//		}
				
	}

}
